Skip to content

Add C# syntax highlighting - #233

Merged
brendt merged 3 commits into
tempestphp:mainfrom
eas4ai:add-csharp-highlighting
Oct 26, 2026
Merged

brendt merged 3 commits into
tempestphp:mainfrom
eas4ai:add-csharp-highlighting

Conversation

@eas4ai

@eas4ai eas4ai commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Register csharp, cs, and c#
  • Highlight preprocessor directives, namespaces and using directives, attributes, comments and XML documentation, regular, verbatim, interpolated, and raw strings, character literals, numbers, keywords, built-in and declared types, declarations, generics, literals, methods, properties, lambdas, operators, and punctuation
  • Reuse the shared C-like comment and operator patterns under src/Languages/CLike/ (the same files as in the C/C++ PR, so this PR also stands alone)
  • Add focused tests and a benchmark fixture

This is a clean resubmission of the closed #225, based directly on main: no core changes and no visual test harness.

Verification

  • vendor/bin/php-cs-fixer fix --allow-risky=yes — no remaining changes
  • vendor/bin/phpstan analyse src tests — no errors
  • vendor/bin/phpunit — 869 tests, 1,134 assertions
  • vendor/bin/phpbench run tests/Bench/HighlighterBench.php --variant='^csharp$' --report=aggregate — 500.45 μs (±0.37%)

Screenshot

C# highlighting in dark mode

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Benchmark Results

Comparison of add-csharp-highlighting against main (052c7bded0f832ea51783edeb1c24d9f97d236c8).

Open to see the benchmark results
benchmark subject set revs its mem_peak mode rstdev
HighlighterBench benchParse apache 100 5 2.146mb +0.34% 72.146360μs -0.55% ±0.95% +107.55%
HighlighterBench benchParse bash 100 5 2.179mb +0.34% 201.462603μs -0.14% ±0.93% +61.07%
HighlighterBench benchParse bbcode 100 5 2.134mb +0.35% 72.647260μs -0.38% ±0.92% -24.39%
HighlighterBench benchParse blade 100 5 2.818mb +0.26% 1,103.866086μs +0.81% ±1.45% +29.55%
HighlighterBench benchParse csharp 100 5 ERR 371.063131μs +0.00% ±1.07% +0.00%
HighlighterBench benchParse c 100 5 2.172mb +0.34% 160.460685μs +0.64% ±0.61% -39.81%
HighlighterBench benchParse cpp 100 5 2.211mb +0.33% 243.355108μs +0.45% ±0.46% -46.98%
HighlighterBench benchParse css 100 5 2.166mb +0.34% 139.732740μs -1.26% ±0.91% -60.85%
HighlighterBench benchParse diff 100 5 2.169mb +0.34% 94.806027μs -0.48% ±0.96% -33.43%
HighlighterBench benchParse dockerfile 100 5 2.138mb +0.34% 87.180489μs -0.06% ±0.73% -1.01%
HighlighterBench benchParse dotenv 100 5 2.150mb +0.34% 76.350744μs +0.34% ±1.81% +300.18%
HighlighterBench benchParse gdscript 100 5 2.246mb +0.33% 328.633053μs -0.23% ±0.41% +5.51%
HighlighterBench benchParse go 100 5 2.125mb +0.35% 145.721918μs -0.04% ±0.54% -50.51%
HighlighterBench benchParse graphql 100 5 2.166mb +0.34% 149.463366μs -0.38% ±1.01% +57.66%
HighlighterBench benchParse html 100 5 2.169mb +0.34% 114.888767μs +0.34% ±0.28% -44.81%
HighlighterBench benchParse http 100 5 2.138mb +0.34% 23.768082μs -1.27% ±0.21% -57.18%
HighlighterBench benchParse ini 100 5 2.154mb +0.34% 85.525029μs +0.89% ±0.66% +16.76%
HighlighterBench benchParse java 100 5 2.570mb +0.29% 304.944560μs +0.68% ±0.31% -24.40%
HighlighterBench benchParse javascript 100 5 2.234mb +0.33% 268.587260μs +1.20% ±0.70% +46.67%
HighlighterBench benchParse json 100 5 2.210mb +0.33% 235.322877μs -0.18% ±0.38% -75.69%
HighlighterBench benchParse kotlin 100 5 2.462mb +0.30% 273.142329μs -0.66% ±0.42% -38.38%
HighlighterBench benchParse markdown 100 5 2.156mb +0.34% 76.015303μs -0.49% ±0.53% -50.18%
HighlighterBench benchParse nginx 100 5 2.220mb +0.33% 260.380705μs -0.48% ±0.59% +26.57%
HighlighterBench benchParse php 100 5 2.513mb +0.29% 748.435323μs +0.02% ±0.35% -65.18%
HighlighterBench benchParse python 100 5 2.413mb +0.31% 416.618376μs +0.03% ±0.41% -22.98%
HighlighterBench benchParse ruby 100 5 2.455mb +0.30% 235.390137μs -0.18% ±0.21% -49.39%
HighlighterBench benchParse rust 100 5 2.398mb +0.31% 186.100000μs -0.34% ±0.28% -32.67%
HighlighterBench benchParse scss 100 5 2.181mb +0.34% 180.933796μs -0.04% ±0.80% +172.00%
HighlighterBench benchParse sema 100 5 2.350mb +0.31% 223.487906μs -0.33% ±0.72% +191.36%
HighlighterBench benchParse sql 100 5 2.180mb +0.34% 157.573288μs +0.40% ±2.01% +323.84%
HighlighterBench benchParse svelte 100 5 2.457mb +0.30% 1,065.249315μs +0.45% ±0.34% -70.20%
HighlighterBench benchParse swift 100 5 2.228mb +0.33% 247.100959μs -0.02% ±0.43% +10.10%
HighlighterBench benchParse terminal 100 5 2.175mb +0.34% 181.082074μs -1.16% ±0.91% +115.36%
HighlighterBench benchParse terraform 100 5 2.180mb +0.34% 172.692055μs +0.47% ±0.51% +129.78%
HighlighterBench benchParse typescript 100 5 2.610mb +0.28% 250.705949μs -0.43% ±0.20% -79.81%
HighlighterBench benchParse txt 100 5 2.109mb +0.35% 8.317534μs -0.33% ±1.66% +45.18%
HighlighterBench benchParse twig 100 5 19.288mb +0.04% 1,548.989706μs -0.37% ±0.61% -13.49%
HighlighterBench benchParse vue 100 5 2.465mb +0.30% 409.020020μs -0.25% ±0.40% +30.47%
HighlighterBench benchParse xml 100 5 2.185mb +0.34% 177.415890μs +0.21% ±0.53% +149.07%
HighlighterBench benchParse yaml 100 5 2.241mb +0.33% 317.203425μs +0.47% ±0.34% -26.73%
HighlighterBench benchParse jsx 100 5 2.177mb +0.34% 51.381292μs -1.76% ±1.06% -7.32%
HighlighterBench benchParse tsx 100 5 2.264mb +0.33% 76.922055μs -0.87% ±0.61% -78.17%

Generated by phpbench against commit 563d5d2

@brendt brendt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add pattern tests please? Look at any other language pattern to see how they work.

@eas4ai

eas4ai commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Added #[PatternTest] attributes to all 18 pattern classes in this PR: 5 shared C-like patterns and 13 CSharp patterns.

Verified locally before pushing: vendor/bin/phpunit — 905 tests, 1,170 assertions; vendor/bin/phpstan analyse src tests — no errors; PHP-CS-Fixer clean.

@eas4ai
eas4ai force-pushed the add-csharp-highlighting branch from 0e22cdc to 39d66e1 Compare October 20, 2026 10:36
@eas4ai

eas4ai commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main to resolve the conflicts in src/Highlighter.php and tests/Bench/HighlighterBench.php after the recent language merges. The C# changes and pattern tests are unchanged apart from fitting the updated registration and benchmark lists.

Verified locally after the rebase: vendor/bin/phpunit — 1201 tests, 1723 assertions; PHPStan reports no errors. GitHub now reports this PR as mergeable with all checks passing.

@eas4ai
eas4ai force-pushed the add-csharp-highlighting branch from 39d66e1 to 56776fc Compare October 20, 2026 10:39
@brendt

brendt commented Oct 26, 2026

Copy link
Copy Markdown
Member

I'll fix the QA check on main, thanks!

@brendt
brendt merged commit 3df5707 into tempestphp:main Oct 26, 2026
4 of 5 checks passed
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 40333401266

Coverage increased (+0.08%) to 94.839%

Details

  • Coverage increased (+0.08%) from the base build.
  • Patch coverage: 46 of 46 lines across 15 files are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 3139
Covered Lines: 2977
Line Coverage: 94.84%
Coverage Strength: 85.92 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants